package com.dji.wpmz;

import java.nio.ByteBuffer;
import java.util.List;

/**
 * JNI 接口类，用于调用 WPMZ 动态库
 */
public class WpmzJni {
    
    static {
        // 加载动态库
        System.loadLibrary("WpmzJni");
    }
    
    /**
     * 将 Document 对象打包为字节数组
     * @param doc Document 对象
     * @return 打包后的字节数组
     */
    public native byte[] pack(Document doc);
    
    /**
     * 从字节数组解包为 Document 对象
     * @param data 字节数组
     * @return 解包后的 Document 对象
     */
    public native Document unpack(byte[] data);
    
    /**
     * 将 Document 转换为 KML 格式的字符串
     * @param doc Document 对象
     * @return KML 字符串
     */
    public native String toTemplate(Document doc);
    
    /**
     * 将 Document 转换为 Waylines 格式的字符串
     * @param doc Document 对象
     * @return Waylines 字符串
     */
    public native String toWaylines(Document doc);
    
    /**
     * Document 类，对应 C++ 中的 wpml::Document
     */
    public static class Document {
        public long createTime;
        public long updateTime;
        public MissionConfig missionConfig;
        public Wayline wayline;
        
        public Document() {
            missionConfig = new MissionConfig();
            wayline = new Wayline();
        }
    }
    
    /**
     * MissionConfig 类，对应 C++ 中的 wpml::MissionConfig
     */
    public static class MissionConfig {
        public int flyToWaylineMode;
        public int finishAction;
        public int exitOnRCLost;
        public int takeOffSecurityHeight;
        public int globalTransitionalSpeed;
        public DroneInfo droneInfo;
        public PayloadInfo payloadInfo;
        
        public MissionConfig() {
            droneInfo = new DroneInfo();
            payloadInfo = new PayloadInfo();
        }
    }
    
    /**
     * DroneInfo 类，对应 C++ 中的 wpml::DroneInfo
     */
    public static class DroneInfo {
        public int droneEnumValue;
        public int droneSubEnumValue;
    }
    
    /**
     * PayloadInfo 类，对应 C++ 中的 wpml::PayloadInfo
     */
    public static class PayloadInfo {
        public int payloadEnumValue;
        public int payloadSubEnumValue;
        public int payloadPositionIndex;
    }
    
    /**
     * Wayline 类，对应 C++ 中的 wpml::Wayline
     */
    public static class Wayline {
        public int templateType;
        public int gimbalPitchMode;
        public int globalWaypointTurnMode;
        public int executeHeightMode;
        public boolean useGlobalTransitionalSpeed;
        public boolean caliFlightEnable;
        public int templateId;
        public int autoFlightSpeed;
        public int transitionalSpeed;
        public int waylineId;
        public double distance;
        public double duration;
        public CoordinateSysParam coordinateSysParam;
        public HeadingParam globalHeadingParam;
        public List<Waypoint> waypoints;
        
        public Wayline() {
            coordinateSysParam = new CoordinateSysParam();
            globalHeadingParam = new HeadingParam();
        }
    }
    
    /**
     * CoordinateSysParam 类，对应 C++ 中的 wpml::WaylineCoordinateSysParam
     */
    public static class CoordinateSysParam {
        public int coordinateMode;
        public int heightMode;
        public int positioningType;
        public int globalHeight;
    }
    
    /**
     * HeadingParam 类，对应 C++ 中的 wpml::WaypointHeadingParam
     */
    public static class HeadingParam {
        public int waypointHeadingMode;
        public boolean waypointHeadingAngleEnable;
        public int waypointHeadingAngle;
        public String waypointPoiPoint;
    }
    
    /**
     * TurnParam 类，对应 C++ 中的 wpml::WaypointTurnParam
     */
    public static class TurnParam {
        public int waypointTurnMode;
        public int waypointTurnDampingDist;
    }
    
    /**
     * Waypoint 类，对应 C++ 中的 wpml::WaypointT
     */
    public static class Waypoint {
        public double longitude;
        public double latitude;
        public int ellipsoidHeight;
        public int height;
        public int executeHeight;
        public int waypointSpeed;
        public boolean useGlobalHeight;
        public boolean useGlobalSpeed;
        public boolean useGlobalHeadingParam;
        public boolean useGlobalTurnParam;
        public boolean useStraightLine;
        public HeadingParam headingParam;
        public TurnParam turnParam;
        
        public Waypoint() {
            headingParam = new HeadingParam();
            turnParam = new TurnParam();
        }
        
        public Waypoint(double longitude, double latitude) {
            this();
            this.longitude = longitude;
            this.latitude = latitude;
        }
    }
}

